﻿#include "GUI.h"
#include "DIALOG.h"
#include "CreateWidget.h"
#include "AppFunction.h"
#include "common_path.h"
#include "password.h"


#define LANGUAGE_SETTING     (SUB_TYPE + 0)
#define DISPLAY_SETTING      (SUB_TYPE + 1)
#define CIPHER_SETTING		 (SUB_TYPE + 2)


 PARA_TCB setting_widget[17];


void setting_widget_create(WM_HWIN hParent){


	setting_widget[0].guiTCB.winType = WIDGET_WINDOW;
	setting_widget[0].guiTCB.xPos = 0;
	setting_widget[0].guiTCB.yPos = 0;
	setting_widget[0].guiTCB.xSize = 720;
	setting_widget[0].guiTCB.ySize = 720;
	setting_widget[0].appTCB.funType = GROUP_SET;
	setting_widget[0].appTCB.addrList = 0;
	setting_widget[0].guiTCB.id = GetUniqueID();
	setting_widget[0].pPreviousLayer = NULL;
	setting_widget[0].pNextLayer = NULL;
	setting_widget[0].pParallelNext = &setting_widget[1];
	setting_widget[0].parent = 0;    // 2级页面父窗口是桌面
	setting_widget[0].winLayer = 2;
	setting_widget[0].transparency = 1;
	setting_widget[0].guiTCB.pRedraw = draw_line;
	SetPictureHmem(&setting_widget[0], 0, 0, GetPicturePathHmem(I_DTA_PATH_BGHOME));



	setting_widget[1].guiTCB.winType = WIDGET_STATIC_TEXT;
	AddStringToBuffer(setting_widget[1].guiTCB.winName, "设置");
	setting_widget[1].guiTCB.xPos = 290;
	setting_widget[1].guiTCB.yPos = 36;
	setting_widget[1].guiTCB.xSize = 140;
	setting_widget[1].guiTCB.ySize = 40;
	setting_widget[1].appTCB.funType = SWITCH_ACTUATOR;
	setting_widget[1].appTCB.addrList = 0;
	setting_widget[1].guiTCB.id = GetUniqueID();
	setting_widget[1].pPreviousLayer = NULL;
	setting_widget[1].pNextLayer = NULL;
	setting_widget[1].pParallelNext = &setting_widget[2];
	setting_widget[1].parent = NULL;



	setting_widget[2].guiTCB.winType = WIDGET_STATIC_TEXT;
	AddStringToBuffer(setting_widget[2].guiTCB.winName, "熄屏时间");
	setting_widget[2].guiTCB.xPos = 92;
	setting_widget[2].guiTCB.yPos = 145;
	setting_widget[2].guiTCB.xSize = 120;
	setting_widget[2].guiTCB.ySize = 60;
	setting_widget[2].appTCB.funType = SWITCH_ACTUATOR;
	setting_widget[2].appTCB.addrList = 0;
	setting_widget[2].guiTCB.id = GetUniqueID();
	setting_widget[2].pPreviousLayer = NULL;
	setting_widget[2].pNextLayer = NULL;
	setting_widget[2].pParallelNext = &setting_widget[3];
	setting_widget[2].parent = NULL;




	setting_widget[3].guiTCB.winType = WIDGET_STATIC_TEXT;
	//strcat(setting_widget[3].guiTCB.winName, "亮度                                     >");
	AddStringToBuffer(setting_widget[3].guiTCB.winName, "亮度");
	setting_widget[3].guiTCB.xPos = 80;
	setting_widget[3].guiTCB.yPos = 245;
	setting_widget[3].guiTCB.xSize = 100;
	setting_widget[3].guiTCB.ySize = 60;
	setting_widget[3].appTCB.funType = SWITCH_ACTUATOR;
	setting_widget[3].appTCB.addrList = 0;
	setting_widget[3].guiTCB.id = GetUniqueID();
	setting_widget[3].pPreviousLayer = NULL;
	setting_widget[3].pNextLayer = NULL;
	setting_widget[3].pParallelNext = &setting_widget[4];
	setting_widget[3].parent = NULL;



	setting_widget[4].guiTCB.winType = WIDGET_STATIC_TEXT;
	AddStringToBuffer(setting_widget[4].guiTCB.winName, "语言切换");
	setting_widget[4].guiTCB.xPos = 92;
	setting_widget[4].guiTCB.yPos = 345;
	setting_widget[4].guiTCB.xSize = 120;
	setting_widget[4].guiTCB.ySize = 60;
	setting_widget[4].appTCB.funType = SWITCH_ACTUATOR;
	setting_widget[4].appTCB.addrList = 0;
	setting_widget[4].guiTCB.id = GetUniqueID();
	setting_widget[4].pPreviousLayer = NULL;
	setting_widget[4].pNextLayer = NULL;
	setting_widget[4].pParallelNext = &setting_widget[5];
	setting_widget[4].parent = NULL;


	setting_widget[5].guiTCB.winType = WIDGET_STATIC_TEXT;
	//AddStringToBuffer(setting_widget[5].guiTCB.winName, "屏保锁                                                           >");
	AddStringToBuffer(setting_widget[5].guiTCB.winName, "修改密码");
	setting_widget[5].guiTCB.xPos = 92;
	setting_widget[5].guiTCB.yPos = 445;
	setting_widget[5].guiTCB.xSize = 120;
	setting_widget[5].guiTCB.ySize = 60;
	setting_widget[5].appTCB.funType = SWITCH_ACTUATOR;
	setting_widget[5].appTCB.addrList = 0;
	setting_widget[5].guiTCB.id = GetUniqueID();
	setting_widget[5].pPreviousLayer = NULL;
	setting_widget[5].pNextLayer = NULL;
	setting_widget[5].pParallelNext = &setting_widget[6];
	setting_widget[5].parent = NULL;


	setting_widget[6].guiTCB.winType = WIDGET_STATIC_TEXT;
	AddStringToBuffer(setting_widget[6].guiTCB.winName, "版本信息                                                         1.00");
	setting_widget[6].guiTCB.xPos = 92;
	setting_widget[6].guiTCB.yPos = 545;
	setting_widget[6].guiTCB.xSize = 560;
	setting_widget[6].guiTCB.ySize = 60;
	setting_widget[6].appTCB.funType = SWITCH_ACTUATOR;
	setting_widget[6].appTCB.addrList = 0;
	setting_widget[6].guiTCB.id = GetUniqueID();
	setting_widget[6].pPreviousLayer = NULL;
	setting_widget[6].pNextLayer = NULL;
	setting_widget[6].pParallelNext = &setting_widget[7];
	setting_widget[6].parent = NULL;


	setting_widget[7].guiTCB.winType = WIDGET_BUTTON;
	setting_widget[7].guiTCB.xPos = 0;
	setting_widget[7].guiTCB.yPos = 20;
	setting_widget[7].guiTCB.xSize = 120;
	setting_widget[7].guiTCB.ySize = 120;
	setting_widget[7].appTCB.funType = RETURN_FUNCTION;
	setting_widget[7].appTCB.addrList = 0;
	setting_widget[7].guiTCB.id = GetUniqueID();
	setting_widget[7].pPreviousLayer = NULL;
	setting_widget[7].pNextLayer = NULL;
	setting_widget[7].pParallelNext = &setting_widget[8];
	setting_widget[7].parent = NULL;
	sprintf(setting_widget[7].guiTCB.onPath, "%s", RETURN);
	sprintf(setting_widget[7].guiTCB.offPath, "%s", RETURN);



	setting_widget[8].guiTCB.winType = WIDGET_BUTTON;
	strcat(setting_widget[8].guiTCB.winName, "");
	setting_widget[8].guiTCB.xPos = 50;
	setting_widget[8].guiTCB.yPos = 156;
	setting_widget[8].guiTCB.xSize = 48;
	setting_widget[8].guiTCB.ySize = 48;
	setting_widget[8].appTCB.funType = WINDOW_NONE;
	setting_widget[8].appTCB.addrList = 0;
	setting_widget[8].guiTCB.id = GetUniqueID();
	setting_widget[8].pPreviousLayer = NULL;
	setting_widget[8].pNextLayer = NULL;
	setting_widget[8].pParallelNext = &setting_widget[9];
	setting_widget[8].parent = NULL;
	sprintf(setting_widget[8].guiTCB.onPath, "%s", DTA_SET_UPDATE);
	sprintf(setting_widget[8].guiTCB.offPath, "%s", DTA_SET_UPDATE);

	setting_widget[9].guiTCB.winType = WIDGET_BUTTON;
	strcat(setting_widget[9].guiTCB.winName, "");
	setting_widget[9].guiTCB.xPos = 50;
	setting_widget[9].guiTCB.yPos = 256;
	setting_widget[9].guiTCB.xSize = 48;
	setting_widget[9].guiTCB.ySize = 48;
	setting_widget[9].appTCB.funType = WINDOW_NONE;
	setting_widget[9].appTCB.addrList = 0;
	setting_widget[9].guiTCB.id = GetUniqueID();
	setting_widget[9].pPreviousLayer = NULL;
	setting_widget[9].pNextLayer = NULL;
	setting_widget[9].pParallelNext = &setting_widget[10];
	setting_widget[9].parent = NULL;
	sprintf(setting_widget[9].guiTCB.onPath, "%s", DTA_SET_LIGHT);
	sprintf(setting_widget[9].guiTCB.offPath, "%s", DTA_SET_LIGHT);

	setting_widget[10].guiTCB.winType = WIDGET_BUTTON;
	strcat(setting_widget[10].guiTCB.winName, "");
	setting_widget[10].guiTCB.xPos = 50;
	setting_widget[10].guiTCB.yPos = 356;
	setting_widget[10].guiTCB.xSize = 48;
	setting_widget[10].guiTCB.ySize = 48;
	setting_widget[10].appTCB.funType = WINDOW_NONE;
	setting_widget[10].appTCB.addrList = 0;
	setting_widget[10].guiTCB.id = GetUniqueID();
	setting_widget[10].pPreviousLayer = NULL;
	setting_widget[10].pNextLayer = NULL;
	setting_widget[10].pParallelNext = &setting_widget[11];
	setting_widget[10].parent = NULL;
	sprintf(setting_widget[10].guiTCB.onPath, "%s", DTA_SET_LANGUAGE);
	sprintf(setting_widget[10].guiTCB.offPath, "%s", DTA_SET_LANGUAGE);


	setting_widget[11].guiTCB.winType = WIDGET_BUTTON;
	strcat(setting_widget[11].guiTCB.winName, "");
	setting_widget[11].guiTCB.xPos = 50;
	setting_widget[11].guiTCB.yPos = 456;
	setting_widget[11].guiTCB.xSize = 48;
	setting_widget[11].guiTCB.ySize = 48;
	setting_widget[11].appTCB.funType = WINDOW_NONE;
	setting_widget[11].appTCB.addrList = 0;
	setting_widget[11].guiTCB.id = GetUniqueID();
	setting_widget[11].pPreviousLayer = NULL;
	setting_widget[11].pNextLayer = NULL;
	setting_widget[11].pParallelNext = &setting_widget[12];
	setting_widget[11].parent = NULL;
	sprintf(setting_widget[11].guiTCB.onPath, "%s", DTA_SET_LOCK);
	sprintf(setting_widget[11].guiTCB.offPath, "%s", DTA_SET_LOCK);


	setting_widget[12].guiTCB.winType = WIDGET_BUTTON;
	strcat(setting_widget[12].guiTCB.winName, "");
	setting_widget[12].guiTCB.xPos = 50;
	setting_widget[12].guiTCB.yPos = 556;
	setting_widget[12].guiTCB.xSize = 48;
	setting_widget[12].guiTCB.ySize = 48;
	setting_widget[12].appTCB.funType = WINDOW_NONE;
	setting_widget[12].appTCB.addrList = 0;
	setting_widget[12].guiTCB.id = GetUniqueID();
	setting_widget[12].pPreviousLayer = NULL;
	setting_widget[12].pNextLayer = NULL;
	setting_widget[12].pParallelNext = NULL;
	setting_widget[12].parent = NULL;
	sprintf(setting_widget[12].guiTCB.onPath, "%s", DTA_SET_SETLOCK);
	sprintf(setting_widget[12].guiTCB.offPath, "%s", DTA_SET_SETLOCK);


	setting_widget[13].guiTCB.winType = WIDGET_CHECKBOX; // 复选框
	setting_widget[13].guiTCB.xPos = 612;
	setting_widget[13].guiTCB.yPos = 440;
	setting_widget[13].guiTCB.xSize = 48;
	setting_widget[13].guiTCB.ySize = 48;
	setting_widget[13].appTCB.funType = CIPHER_SETTING;
	setting_widget[13].appTCB.addrList = 0;
	setting_widget[13].guiTCB.id = GetUniqueID();
	setting_widget[13].pPreviousLayer = NULL;
	setting_widget[13].pNextLayer = NULL;
	setting_widget[13].pParallelNext = NULL;
	setting_widget[13].parent = NULL;


	setting_widget[14].guiTCB.winType = WIDGET_SLIDE; // 调整亮度
	setting_widget[14].guiTCB.xPos = 360;
	setting_widget[14].guiTCB.yPos = 250;
	setting_widget[14].guiTCB.xSize = 300;
	setting_widget[14].guiTCB.ySize = 40;
	setting_widget[14].appTCB.funType = SWITCH_ACTUATOR;
	setting_widget[14].appTCB.addrList = 0;
	setting_widget[14].guiTCB.specialInfo.slider.useFlag = 1;
	setting_widget[14].guiTCB.specialInfo.slider.rangeStart = 0;
	setting_widget[14].guiTCB.specialInfo.slider.rangeEnd = 9;
	setting_widget[14].guiTCB.specialInfo.slider.thumbWidth = 10;
	setting_widget[14].guiTCB.id = GetUniqueID();
	setting_widget[14].pPreviousLayer = NULL;
	setting_widget[14].pNextLayer = NULL;
	setting_widget[14].pParallelNext = NULL;
	setting_widget[14].parent = NULL;
	/*sprintf(setting_widget[14].guiTCB.onPath, "%s", DTA_TEMP_SLIDER_BTN);
	sprintf(setting_widget[14].guiTCB.offPath, "%s", DTA_TEMP_SLIDER_BTN);
	ConfigureBitMap(DTA_TEMP_SLIDER, &setting_widget[14].guiTCB.pictureBack, 1);
*/

	setting_widget[15].guiTCB.winType = WIDGET_DROPDOWN;
	setting_widget[15].guiTCB.xPos = 360;
	setting_widget[15].guiTCB.yPos = 345;
	setting_widget[15].guiTCB.xSize = 300;
	setting_widget[15].guiTCB.ySize = 200;
	setting_widget[15].appTCB.funType = LANGUAGE_SETTING;
	setting_widget[15].appTCB.addrList = 0;
	setting_widget[15].guiTCB.id = GetUniqueID();
	setting_widget[15].guiTCB.pFont = &GUI_FONT_48;
	setting_widget[15].pPreviousLayer = NULL;
	setting_widget[15].pNextLayer = NULL;
	setting_widget[15].pParallelNext = NULL;
	setting_widget[15].parent = NULL;

	
	setting_widget[16].guiTCB.winType = WIDGET_DROPDOWN;
	setting_widget[16].guiTCB.xPos = 360;
	setting_widget[16].guiTCB.yPos = 145;
	setting_widget[16].guiTCB.xSize = 300;
	setting_widget[16].guiTCB.ySize = 200;
	setting_widget[16].appTCB.funType = DISPLAY_SETTING;
	setting_widget[16].appTCB.addrList = 0;
	setting_widget[16].guiTCB.id = GetUniqueID();
	setting_widget[16].guiTCB.pFont = &GUI_FONT_48;
	setting_widget[16].pPreviousLayer = NULL;
	setting_widget[16].pNextLayer = NULL;
	setting_widget[16].pParallelNext = NULL;
	setting_widget[16].parent = NULL;



	Concatenate(setting_widget, 17, 2);
	CreateWidget(&setting_widget[0], WM_HBKWIN, 0);


}


void SettingFunction(pPARA_TCB pBase, pPARA_TCB pPara, uint8_t stage)
{
	GUI_HWIN hWin;
	uint8_t language[50] = { 0 };

	if (stage == 0)                                // 初始化
	{
		if (pPara == &setting_widget[15])
		{
			hWin = WM_GetDialogItem(pPara->parent, pPara->guiTCB.id);
			AddStringToBuffer(language, "中文");
			DROPDOWN_SetTextHeight(hWin, 48);
			DROPDOWN_AddString(hWin, language);
			DROPDOWN_AddString(hWin, "English");
		}
		else if (pPara == &setting_widget[16]){
			hWin = WM_GetDialogItem(pPara->parent, pPara->guiTCB.id);
			//AddStringToBuffer(language, "5");
			DROPDOWN_SetTextHeight(hWin, 48);
			DROPDOWN_AddString(hWin, "5s");
			DROPDOWN_AddString(hWin, "10s");
			DROPDOWN_AddString(hWin, "30s");
			DROPDOWN_AddString(hWin, "60s");
		}
	}
	else if (stage == 1)                           // 应用功能
	{
		if (pPara->appTCB.keyMsg == WM_NOTIFICATION_RELEASED)
		{
		
			switch ((pPara->appTCB.funType & NORMAL_MASK))
			{
			case CIPHER_SETTING:
				hWin = WM_GetDialogItem(pPara->parent, pPara->guiTCB.id);
				SetModifyPassword(CHECKBOX_GetState(hWin));
				break;
			}
		}
	}
	else if (stage == 2)                           // 定时器功能
	{
	}
	else if (stage == 3)                           // 选择语言
	{
		switch ((pPara->appTCB.funType & NORMAL_MASK))
		{
		case LANGUAGE_SETTING:
			break;
		case DISPLAY_SETTING:
			break;
		}
	}
}
//
//
//void ChangeLanguage(pPARA_TCB pBase, pPARA_TCB pPara, uint8_t stage)
//{
//	GUI_HWIN hWin;
//	uint8_t language[50] = { 0 };
//
//
//	if (stage == 0)                                // 初始化
//	{
//		if (pPara == &setting_widget[15])
//		{
//			//SetModifyPassword(0);
//			hWin = WM_GetDialogItem(pPara->parent, pPara->guiTCB.id);
//			AddStringToBuffer(language, "中文");
//			DROPDOWN_SetTextHeight(hWin, 48);
//			DROPDOWN_AddString(hWin, language);
//			DROPDOWN_AddString(hWin, "English");
//			//DROPDOWN_AddString(hWin, "XYZ");
//		}
//	}
//	else if (stage == 1)                           // 应用功能
//	{
//	}
//	else if (stage == 2)                           // 定时器功能
//	{
//	}
//	else if (stage == 3)                           // 选择语言
//	{
//
//	}
//}
//
//
//
//void DiplayTime(pPARA_TCB pBase, pPARA_TCB pPara, uint8_t stage)
//{
//	GUI_HWIN hWin;
//	uint8_t language[50] = { 0 };
//
//
//	if (stage == 0)                                // 初始化
//	{
//		if (pPara == &setting_widget[15])
//		{
//			//SetModifyPassword(0);
//			hWin = WM_GetDialogItem(pPara->parent, pPara->guiTCB.id);
//			AddStringToBuffer(language, "中文");
//			DROPDOWN_SetTextHeight(hWin, 48);
//			DROPDOWN_AddString(hWin, language);
//			DROPDOWN_AddString(hWin, "English");
//			//DROPDOWN_AddString(hWin, "XYZ");
//		}
//	}
//	else if (stage == 1)                           // 应用功能
//	{
//	}
//	else if (stage == 2)                           // 定时器功能
//	{
//	}
//	else if (stage == 3)                           // 选择语言
//	{
//
//	}
//}